package dao.wx;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import dao.BaseDAO;
import dao.RowMapper;
import entity.Product;

public class GooscolectionDao extends BaseDAO{
	public List<Product> collectionquery(int id,int curpage,int pagesize ){
		int start=(curpage-1)*pagesize;
		String sql="select tb_collection.collection_id,tb_product.Product_name,tb_product.Product_price from tb_collection,tb_product"
				+ " where tb_collection.Member_id=? and tb_collection.Product_id=tb_product.Product_id limit ?,?";
		List<Product> list=executeQuery(sql, new RowMapper<Product>() {
			@Override
			public Product mapper(ResultSet rs) throws SQLException {
				Product one=new Product();
				one.setProductId(rs.getInt(1));
				one.setProductName(rs.getString(2));
				one.setProductPrice(rs.getDouble(3));
				return one;
			}
		},id,start,pagesize);
		return list;
	}
	public int collectioncount(int id){
		String sql="select count(*) from tb_collection where member_id=?";
		return get(sql, new RowMapper<Integer>() {
			@Override
			public Integer mapper(ResultSet rs) throws SQLException {
				return rs.getInt(1);
			}
		}, id);
	}
	
	public void collectiondelete(int id) {
		String sql="delete from tb_collection where collection_id=?";
		executeUpdate(sql, id);
	}
}
